package ws.jdbc.concurrent.driver.sqlserver.tds;

import java.sql.Date;
import ws.jdbc.concurrent.driver.sqlserver.tds.datatypes.TYPE_INFO;
import ws.jdbc.concurrent.driver.sqlserver.tds.rpc.UpdateValue;

/**
 * Services provided by the TDS Result Set.
 * 
 * @author Wilson Santos, 36228 <wilson.santos@ua.pt>
 */
public interface ITDSResultSet {

  /**
   * Get the cursor handler for the result set.
   *
   * @return cursor handle.
   */
  public int getCursor();

  /**
   * Get the number of columns on the result set.
   * 
   * @return number of columns.
   */
  public int columnCount();

  /**
   * Get the number of rows on the result set.
   *
   * @return number of rows.
   */
  public int rowCount();

  /**
   * Get the row count for SQL Data Manipulation Language (DML) statements.
   * 
   * @return row count for SQL Data Manipulation Language (DML) statements.
   */
  public int getUpdateRowCount();

  /**
   * Check if the result set is empty.
   * 
   * @return {@code true} if is empty, otherwise {@code false}.
   */
  public boolean isEmpty();

  /**
   * Get one {@code integer} value from the result set.
   *
   * @param rowNumber row number.
   * @param columnNumber column number.
   *
   * @return value read.
   */
  public int getInt(final int rowNumber, final int columnNumber);

  /**
   * Get one {@code string} value from the result set.
   *
   * @param rowNumber row number.
   * @param columnNumber column number.
   *
   * @return value read.
   */
  public String getString(final int rowNumber, final int columnNumber);

  /**
   * Get one {@code float} value from the result set.
   *
   * @param rowNumber row number.
   * @param columnNumber column number.
   *
   * @return value read.
   */
  public float getFloat(final int rowNumber, final int columnNumber);

  /**
   * Get one {@code double} value from the result set.
   *
   * @param rowNumber row number.
   * @param columnNumber column number.
   *
   * @return value read.
   */
  public double getDouble(final int rowNumber, final int columnNumber);

  /**
   * Get one {@code date} value from the result set.
   *
   * @param rowNumber row number.
   * @param columnNumber column number.
   *
   * @return value read.
   */
  public Date getDate(final int rowNumber, final int columnNumber);

  /**
   * Get column name.
   *
   * @param columnIndex column number whose name will be retrieved.
   *
   * @return column name.
   */
  public String getColumnName(int columnIndex);

  /**
   * Get column information about its type.
   *
   * @param columnIndex column number whose information will be retrieved.
   *
   * @return column type information.
   */
  public TYPE_INFO getColumnInfo(int columnIndex);

  /**
   * Get the table that generated the result set.
   *
   * @return table name.
   */
  public String getTableName();

  /**
   * Add row to the result set.
   *
   * @param tdsResultSet add the rows from this result set.
   */
  public void addRows(ITDSResultSet tdsResultSet);

  /**
   * Replace the result set rows.
   *
   * @param tdsResultSet
   */
  public void replaceRows(ITDSResultSet tdsResultSet);

  /**
   * Update row values.
   *
   * @param rowIndex number of the row to update.
   * @param tdsResultSet copy the row values from this object. It'll be copied the first row.
   */
  public void updateRow(int rowIndex, RowTokenReader row);

  /**
   * Update row values.
   *
   * @param rowIndex number of the row to update.
   * @param updateRow new values.
   */
  public void updateRow(int rowIndex, UpdateValue[] updateValues);

  /**
   * Insert a new row at the end of the result set.
   *
   * Its main purpose is to be used on a cursor with shared cache.
   *
   * @param updateRow values to insert.
   */
  public void insertValues(UpdateValue[] updateValues);

  /**
   * Check whether the last column read had a value of SQL {@code NULL}.
   *
   * @param rowNumber row number.
   * @param columnNumber column number.
   *
   * @return {@code true} if the last column value read was SQL {@code NULL}, otherwise {@code otherwise}.
   */
  public boolean wasNull(int rowNumber, int columnNumber);

  public RowTokenReader getRow(int rowIndex);
  public ColMetadataTokenReader getColumnMetadata();
}
